package com.xzx.java.kit.util;

import java.time.DayOfWeek;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

/**
 * @version 1.0
 * @auther xinzhixuan
 * @date 2022/4/22 19:00
 */
public class DateUtil {

    /**
     * 获取指定时间的周一
     *
     * @param timestamp .
     * @return .
     */
    public static String getMonday(long timestamp) {
        return Instant.ofEpochMilli(timestamp).atZone(ZoneId.systemDefault()).with(DayOfWeek.MONDAY)
                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    /**
     * 获取当前时间下周一
     * @return .
     */
    public static String getNextMonday() {
        return LocalDate.now().with(TemporalAdjusters.next(DayOfWeek.MONDAY))
                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    public static void main(String[] args) {
        System.out.println(getMonday(System.currentTimeMillis()));
        System.out.println(getNextMonday());
    }

}
